﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;//数据库操作需要引入的命名空间
using System.Security.Cryptography;//MD5加密需引入的命名空间

namespace DataBase
{
    public class ConToDB
    {
        /// <summary>
        /// 建立连接
        /// </summary>
        /// <returns></returns>
        private SqlConnection getConn()
        {
            return new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"].toString());

        }
        /// <summary>
        /// 执行sql语句
        /// </summary>
        /// <returns></returns>
        public int sqlEx(string cmdStr,string username,string password)
        {
            SqlConnection con = getConn();//连接数据库
            //判断连接是否打开
            if (con.State != ConnectionState.Open)
            {
                con.Open();//打开连接            
            }
            SqlCommand cmd = new SqlCommand(cmdStr, con);
            cmd.Parameters.Add("NAME",SqlDbType.VarChar);
            cmd.Parameters.Add("PASSWORD", SqlDbType.VarChar);
            cmd.Parameters[NAME] = username;
            cmd.Parameters[PASSWORD] = password;

            SqlDataReader result = cmd.ExecuteReader();
            if (result.Read() == true)
            { 
                Session
            }
            try
            {
                cmd.EndExecuteNonQuery();//执行SQL语句并返回受影响的行数
                return 1;
            }
            catch (Exception e)
            {
                return 0;
            }
            finally
            {
                //判断连接是否关闭
                if (con.State == ConnectionState.Open)
                {
                    con.Dispose();//释放连接资源            
                }
            }


        }



       



    }




}
